package com.youchuang.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Repository;

import com.youchuang.bean.Bulltion;
import com.youchuang.common.HibernateConnection;
import com.youchuang.dao.BulltionDAO;

@Repository("BulltionDAO")
public class BulltionDAOImpl implements BulltionDAO {
	private static String HQL_FIND_BULLTION_BY_ID = "from Bulltion where id = :id";
	private static final String HQL_FIND_ALL_BULLTION = "from Bulltion";
	@Resource
	private HibernateConnection<Bulltion> hibernateConnection;

	@Override
	public void save(Bulltion t) {
		hibernateConnection.save(t);
	}

	@Override
	public void delete(Bulltion t) {
		// Do nothing because of it unusual
	}

	@Override
	public int update(Bulltion t) {
		// Do nothing because of it unusual
		return 0;
	}

	@Override
	public List<Bulltion> queryAll() {
		return hibernateConnection.find(HQL_FIND_ALL_BULLTION);
	}

	@Override
	public Bulltion queryBulltionById(String id) {
		Map<String, Object> params = new HashMap<>();
		params.put("id", id);
		List<Bulltion> list = hibernateConnection.find(HQL_FIND_BULLTION_BY_ID, params);
		if (CollectionUtils.isEmpty(list)) {
			return null;
		}
		return list.get(0);
	}

}
